<template>
  <div id="main">
    <nav class="homenav">
      <div class="navtitle"><strong>萌宠</strong>| MYPETSTORE</div>
      <a @click="toMain()">首页</a>
      <a @click="toCatalog()">商品分类</a>
      <a @click="toCart()">购物车</a>
      <a @click="toAccount()">我的账户</a>
      <a @click="toOrder()">我的订单</a>
      <div class="navanim home" id="navanim"></div>
      <div class="none"></div>
    </nav>
    <router-view />
    <footer class="foot">
      <p>@2021-2022</p>
      <p>org.csu</p>
      <p>Cease to struggle and you cease to live</p>
    </footer>
  </div>
</template>

<script>
export default {
  name: "App",
  watch: {
    $route: function (to, from) {
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    },
  },
  methods: {
    toMain() {
      var nav = document.getElementById("navanim");
      nav.className = "navanim home";
      nav.setAttribute("class", "navanim home");
      this.$router.push("/");
    },
    toCatalog() {
      var nav = document.getElementById("navanim");
      nav.className = "navanim catalog";
      nav.setAttribute("class", "navanim catalog");
      this.$router.push("/catalog");
    },
    toCart() {
      var nav = document.getElementById("navanim");
      nav.className = "navanim cart";
      nav.setAttribute("class", "navanim cart");
      this.$router.push("/cart");
    },
    toAccount() {
      var nav = document.getElementById("navanim");
      nav.className = "navanim account";
      nav.setAttribute("class", "navanim account");
      this.$router.push("/account");
    },
    toOrder() {
      var nav = document.getElementById("navanim");
      nav.className = "navanim order";
      nav.setAttribute("class", "navanim order");
      this.$router.push("/order");
    },
  },
};
</script>

<style>
@charset "utf-8";

body {
  margin: 0;
  padding: 0;
  background-image: url(assets/background.jpg);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  overflow-x: hidden;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: rgba(91, 105, 136, 0.8);
}

::-webkit-scrollbar-track {
  background: rgb(194, 213, 241);
}

/*底部part*/
.foot {
  margin-top: 0px;
  width: 100vw;
  height: 100px;
  float: left;
  clear: both;
  text-align: center;
  margin-bottom: 0px;
  background-color: rgba(84, 132, 161, 0.8);
}

.foot p {
  line-height: 10px;
  color: rgb(28, 43, 43);
}

/*主页part*/
.main {
  scroll-snap-type: y mandatory;
  overflow: scroll;
  overflow-x: hidden;
  height: 100vh;
}

/*导航栏part*/
nav {
  position: fixed;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 70px;
  top: 0px;
  background-color: rgb(123, 161, 197);
  overflow: hidden;
  font-size: 20px;
  color: rgb(234, 247, 255);
  opacity: 0.8;
  z-index: 1000;
  transition: 0.5s;
}
.homenav {
  animation: load2 1s linear;
  width: 100%;
}

nav:hover {
  opacity: 0.95;
  transition: 0.5s;
}
nav .navtitle {
  padding-left: 50px;
  width: 30%;
}
nav .navtitle strong {
  font-size: 50px;
  font-weight: bolder;
}
nav a {
  position: absolute;
  float: left;
  display: block;
  justify-content: center;
  text-decoration: none;
  z-index: 1;
  height: inherit;
  line-height: 70px;
  width: 120px;
  text-align: center;
  font-weight: bolder;
  color: rgb(84, 109, 158);
  transition: 0.5s;
}
nav .navanim {
  position: absolute;
  height: inherit;
  z-index: 0;
  background: rgb(155, 200, 240);
  border-radius: 5px;
  left: 0px;
  transition: all 0.5s ease 0s;
  width: 120px;
}
a:nth-child(2) {
  width: 120px;
  left: 35%;
}
a:nth-child(3) {
  width: 120px;
  left: 45%;
}
a:nth-child(4) {
  width: 120px;
  left: 55%;
}
a:nth-child(5) {
  width: 120px;
  left: 65%;
}
a:nth-child(6) {
  width: 120px;
  left: 75%;
}
nav .home,
a:nth-child(2):hover ~ .navanim {
  width: 120px;
  left: 35%;
}

nav .catalog,
a:nth-child(3):hover ~ .navanim {
  width: 120px;
  left: 45%;
}

nav .cart,
a:nth-child(4):hover ~ .navanim {
  width: 120px;
  left: 55%;
}

nav .account,
a:nth-child(5):hover ~ .navanim {
  width: 120px;
  left: 65%;
}
nav .order,
a:nth-child(6):hover ~ .navanim {
  width: 120px;
  left: 75%;
}
nav .none {
  width: 20%;
}

@keyframes load2 {
  0% {
    top: -80px;
    opacity: 0;
  }
  100% {
    top: 0px;
    opacity: 0.8;
  }
}
</style>
